﻿
using MS.Core.BaseProvider;
using ReportDesignerServer.DataModel;
using ReportDesignerServer.IRepository;
using ReportDesignerServer.Models;
using SqlSugar;
using System.Data;


namespace ReportDesignerServer.Repository
{
    public class PrintModelDataRepository : BaseRepository<DictPrintModelDataSrc>, IPrintModelDataRepository
    {
        public PrintModelDataRepository(SqlSugarScope sqlSugarScope) : base(sqlSugarScope)
        {
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="modelName"></param>
        /// <returns></returns>
        public List<DictPrintModelDataSrc> GetModelDatasrcs(string modelName)
        {
            Expressionable<DictPrintModelDataSrc> exp = Expressionable.Create<DictPrintModelDataSrc>();
            exp.And(it => it.PrintModelName == modelName);
            var result = DB.Queryable<DictPrintModelDataSrc>().Where(exp.ToExpression()).ToList();
            return result;
        }

        /// <summary>
        /// 执行sql查询数据
        /// </summary>
        /// <param name="selectSql"></param>
        /// <returns></returns>
        public IEnumerable<dynamic> Select(string selectSql)
        {
            var result = DB.Ado.SqlQuery<dynamic>(selectSql);
            return result;
        }
        /// <summary>
        /// 行转列
        /// </summary>
        /// <param name="selectSql"></param>
        /// <returns></returns>
        public Dictionary<string, DeInfo> RowToCol(string selectSql)
        {
            var result = DB.Ado.SqlQuery<DeInfo>(selectSql).ToDictionary(x => x.ItemName, x => x);
            return result;
        }
    }
}
